<template>
  <div class="block">
    <el-cascader
      :value="value"
      :options="options"
      :props="props"
      separator="-"
      @change="handleChange"
    />
  </div>
</template>

<script>
import { getDepartmentAPI } from '@/api/department'
import { list2Tree } from '@/utils/tree'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      roleIds: [],
      options: [],
      props: {
        expandTrigger: 'hover',
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.dataList()
  },
  methods: {
    async dataList() {
      const { data } = await getDepartmentAPI()
      const result = list2Tree(data, 0)
      this.options = result
    },
    handleChange(arrData) {
      if (arrData.length) {
        this.$emit('input', arrData[arrData.length - 1])
      } else {
        this.$emit('input', '')
      }
    }
  }
}
</script>

<style>
</style>
